package com.qyhl.webtv.commonlib.utils.view.gridviewpager;

import android.content.Context;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import java.util.List;

/**
 * Created by Cookie on 2017/1/16.
 */

public class GridViewPagerAdapter extends PagerAdapter {
    private List<GridView> mLists;



    public GridViewPagerAdapter(Context context, List<GridView> array) {

        this.mLists = array;

    }



    @Override

    public int getCount() {

        return mLists.size();

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view ==object;
    }




    @Override

    public Object instantiateItem(View arg0, int arg1) {

        if (mLists.get(arg1).getParent() != null) {

            ((ViewGroup) mLists.get(arg1).getParent()).removeView(mLists.get(arg1));

        }

        ((ViewPager) arg0).addView(mLists.get(arg1));

        return mLists.get(arg1);

    }



    @Override

    public void destroyItem(View arg0, int arg1, Object arg2) {

        ((ViewPager) arg0).removeView((View) arg2);

    }
}
